//
//  ViewController.m
//  DLT-daluntai
//
//  Created by Apple on 17/3/21.
//  Copyright © 2017年 BW. All rights reserved.
//

#import "ViewController.h"
#import "MainTabBayController.h"
@interface ViewController ()<UIScrollViewDelegate>
    {
        UIScrollView *scroller;
        UIPageControl *pageCon;
    }
    @end

@implementation ViewController
    
- (void)viewDidLoad {
    [super viewDidLoad];
    [self fangaf];
}
-(void)fangaf{
    
    float width=self.view.frame.size.width;
    float height=self.view.frame.size.height;
    
    scroller=[[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, width, height)];
    UIImageView *imag1=[[UIImageView alloc]initWithFrame:CGRectMake(0, 0, width, height)];
    imag1.image=[UIImage imageNamed:@"1.jpg"];
    UIImageView *imag2=[[UIImageView alloc]initWithFrame:CGRectMake(width, 0, width, height)];
    imag2.image=[UIImage imageNamed:@"2.jpg"];
    UIImageView *imag3=[[UIImageView alloc]initWithFrame:CGRectMake(width*2, 0, width, height)];
    imag3.image=[UIImage imageNamed:@"3.jpg"];
    UIImageView *imag4=[[UIImageView alloc]initWithFrame:CGRectMake(width*3, 0, width, height)];
    imag4.image=[UIImage imageNamed:@"4.jpg"];
    // 添加图片
    [scroller addSubview:imag1];
    [scroller addSubview:imag2];
    [scroller addSubview:imag3];
    [scroller addSubview:imag4];
    // 隐藏下划线
    scroller.showsHorizontalScrollIndicator=NO;
    scroller.contentSize=CGSizeMake(width*4, height);
    scroller.pagingEnabled=YES;
    scroller.delegate=self;
    [self.view addSubview:scroller];
    // 初始化
    pageCon=[[UIPageControl alloc]initWithFrame:CGRectMake(width/2-50, height-150, 100, 30)];
    // 页数
    pageCon.numberOfPages=4;
    pageCon.currentPage=0;
    // 颜色
    pageCon.currentPageIndicatorTintColor=[UIColor greenColor];
    pageCon.pageIndicatorTintColor=[UIColor redColor];
    pageCon.userInteractionEnabled=YES;
    [self.view addSubview:pageCon];
}
-(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{
    int initit=scroller.contentOffset.x/self.view.frame.size.width;
    pageCon.currentPage=initit;
}
-(void)scrollViewDidScroll:(UIScrollView *)scrollView{
    UIButton *but=[[UIButton alloc]initWithFrame:CGRectMake(self.view.frame.size.width-160, self.view.frame.size.height-90, 80, 30)];
    CGPoint point=scroller.contentOffset;
    NSInteger intt=point.x/scroller.frame.size.width;
    pageCon.currentPage=intt;
    if (pageCon.currentPage==3) {
        [but setTitle:@"进入" forState:UIControlStateNormal];
        [but setTintColor:[UIColor brownColor]];
        but.backgroundColor=[UIColor greenColor];
        [but addTarget:self action:@selector(rian) forControlEvents:UIControlEventTouchUpInside];
        [self.view addSubview:but];
    }
}
-(void)rian{
    MainTabBayController *mai=[[MainTabBayController alloc]init];
    [self presentViewController:mai animated:NO completion:^{
    }];
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
